from faker import Faker
import logging
import yaml


class TestDatas:

    @classmethod
    def generate_name(cls):
        logging.info("调用generate_name方法,生成姓名")
        return Faker("zh_CN").name()

    @classmethod
    def generate_phone_number(cls):
        logging.info("调用generate_phone_number方法,生成电话号码")
        return Faker("zh_CN").phone_number()

    @classmethod
    def save_to_yaml(cls, yaml_path, datas):
        logging.info(f"调用save_to_yaml方法,写入文件{yaml_path}, 数据： {datas}")
        with open(yaml_path, "w+", encoding="utf8") as f:
            yaml.safe_dump(datas, f, allow_unicode=True)

    @classmethod
    def read_yaml_datas(cls, yaml_path):
        logging.info(f"调用read_yaml_datas方法,读取文件{yaml_path}")
        with open(yaml_path, "r", encoding="utf8") as f:
            return yaml.safe_load(f)
